#include"process.h"

void process()
{
    char buff[SIZE] = {0};
    char str[]="|-\\/";
    int len = strlen(str);
    int rate = MAX_RATE;
    while(rate <= 100)
    {
        printf("[%-100s][%d%%][%c]\r",buff,rate,str[rate%len]);
        fflush(stdout);
        buff[rate++]='#';
        usleep(DELAY);
    }
    printf("\n");
}

void process_v2(double rate)
{
    static char buff[SIZE] = {0};
    char str[]="|-\\/";

    int len = strlen(str);
    static int cnt = 0;
    if(rate <= MAX_RATE  && rate >= 0)
    {
        cnt = (cnt+1)%len;
        printf("[%-100s][%.2lf%%][%c]\r",buff,rate,str[cnt]);
        fflush(stdout);
        if(rate < MAX_RATE)
        {
            buff[(int)rate]=BODY;
            buff[(int)rate+1]=HARD;
        }
        else
        {
            buff[MAX_RATE] = BODY;

        }
    }
    
}


